#!/bin/bash -l

echo 
echo "OpenMPI"
echo "======="

export CMD_LINE_PARAMS=$1 $2 $3 $4 $5 $6 $7 $8 $9

# -bbp data/instance039c1.txt -minPercentForDispatching 50 -maxPercentForDispatching 70 -periodMPITestSlave 0.001 -periodMPITestMaster 0.001instance039c1.txt => 35sec

# -bbp data/instance040c1.txt -minPercentForDispatching 50 -maxPercentForDispatching 70 -periodMPITestSlave 0.001 -periodMPITestMaster 0.001instance039c1.txt => 140sec

#export DEFAULT_DATAFILE="data/instance005a.txt"
#export DEFAULT_DATAFILE="data/instance010a.txt"
export DEFAULT_DATAFILE="data/instance012c1.txt"

if [ $# = 0 ]; then
    export CMD_LINE_PARAMS="-lowerboundV1 -bbp ${DEFAULT_DATAFILE} -minPercentForDispatching 50 -maxPercentForDispatching 70 -periodMPITestSlave 0.001 -periodMPITestMaster 0.001"
fi 

export PROGRAM_NAME=bin/ompi-samebatch-multiproduct-binpacking
export MPIRUN_CMD="mpirun"
export NBR_NODES=4

if (( `hostname` == "pc-gi-90" || `hostname` == "eman" || `hostname` == "pcp-set-26" ))
then
    echo `hostname`
else
    echo mesocluster

    echo module rm/load ompi
    module rm ompi
    module load ompi
fi

# script pouvant etre executer depuis le repertoire parent par 
# la commande script/runmpi
# ou depuis le repertoire src (travail avec emacs)
if [ ! -d "bin" ]; then
    echo moving to parent directory
    cd ..
fi

pwd

export CMD_LINE_PARAMS="${CMD_LINE_PARAMS}"

#mpirun --hostfile bhost -np 2 bin/samebatch-muliproduct-binpacking-mpi $1 $2 $3 $4 $5 $6

echo time ${MPIRUN_CMD} -np ${NBR_NODES} ${PROGRAM_NAME} ${CMD_LINE_PARAMS}

time ${MPIRUN_CMD} -np ${NBR_NODES} ${PROGRAM_NAME} ${CMD_LINE_PARAMS}
 

